package com.example.worldgdpjar.service;

import com.example.worldgdpjar.dao.CityDao;
import com.example.worldgdpjar.model.City;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CityService {

  private final CityDao cityDAO;

  public CityService(CityDao cityDAO) {
    this.cityDAO = cityDAO;
  }

  public List<City> getCities(String countryCode, Integer pageNo) {
    final int pageSize = 10;
    Integer offset = null;
    if (pageNo != null) {
      offset = (pageNo - 1) * pageSize;
    }
    return cityDAO.getCities(countryCode, offset, pageSize);
  }

  public List<City> getCities(String countryCode) {
    return cityDAO.getCities(countryCode, null, 0);
  }
}
